#include <USART.h>

/*ISR(USART_RXC_vect)
{
	switch(UDR)
	{
		default: break;
	}
}*/

void InitUSART()
{
	#define baudrate 19200L
	#define bauddivider (F_CPU/(16*baudrate)-1)
	#define HI(x) ((x)>>8)
	#define LO(x) ((x)&0xff)

	UBRRH=HI(bauddivider);
	UBRRL=LO(bauddivider);
	UCSRA=0;
	UCSRB=1<<RXEN|1<<TXEN|1<<RXCIE|0<<TXCIE;
	UCSRC=1<<UCSZ0|1<<UCSZ1;
}

void USART_Transmit(unsigned char data)
{
	// Wait for empty transmit buffer
	while(!(UCSRA&(1<<UDRE)));
	// Put data into buffer, send the data
	UDR=data;
}

unsigned char USART_Receive(void)
{
	// Wait for data to be received
	while(!(UCSRA&(1<<RXC)));
	// Get and return received data from buffer
	return UDR;
}
